<!--
 * @Description  :
 * @Autor        : guoxi
 * @Date         : 2022-06-16 10:16:50
 * @LastEditors  : Please set LastEditors
 * @LastEditTime : 2022-11-17 11:53:16
 * @FilePath     : \rpms\src\views\project\build\detail\index.vue
-->
<template>
  <el-card>
    <div class="card-wrap">
      <el-page-header content="查看评审" @back="handleBack" />
    </div>
  </el-card>
  <br />

  <el-form
    :model="model.formData"
    :disabled="isDisabled"
    ref="formRef"
    @submit.prevent
    :rules="formRules"
    label-width="140px"
  >
    <el-card>
      <template #header>
        <div class="card-box-header">
          <span>评审发起信息</span>
          <div v-if="show1" @click="show1 = !show1" class="header-btn">
            收起
            <i class="el-icon-arrow-down"></i>
          </div>
          <div v-else @click="show1 = !show1" class="header-btn">
            展开
            <i class="el-icon-arrow-right"></i>
          </div>
        </div>
      </template>
      <div v-show="show1">
        <el-row>
          <el-col :xl="8" :lg="12">
            <el-form-item label="所属项目：">
              {{ model.formData.projectName }}
            </el-form-item>
          </el-col>
          <el-col :xl="8" :lg="12">
            <el-form-item label="项目编号：">
              {{ model.formData.projectCode }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xl="8" :lg="12">
            <el-form-item label="评审项目阶段：">
              {{ model.formData.reviewStageName }}
            </el-form-item>
          </el-col>
          <el-col :xl="8" :lg="12">
            <el-form-item label="评审轮次：">
              {{ model.formData.reviewRoundName }}
            </el-form-item>
          </el-col>
        </el-row>
        <div>
          <common-info
            :projectId="route.query.projectId"
            :reviewStageName="model.formData.reviewStageName"
          ></common-info>
        </div>
        <!-- <div v-if="model.formData.reviewStageName === '项目立项'">
          <el-row>
            <el-col :xl="16" :lg="24">
              <el-form-item label="项目立项书">
                <el-link
                  v-for="(item, index) in defaultProposaFileList"
                  :key="index"
                  @click="handlePreview(item)"
                  >{{ item.fileName }}</el-link
                >
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :xl="16" :lg="24">
              <el-form-item label="项目可行性研究报告">
                <el-link
                  v-for="(item, index) in defaultFileList"
                  :key="index"
                  @click="handlePreview(item)"
                  >{{ item.fileName }}</el-link
                >
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        <div v-if="model.formData.reviewStageName === '项目实施'">
          <el-row>
            <el-col :xl="16" :lg="24">
              <el-form-item label="项目实施计划">
                <el-table
                  :data="tableData"
                  border
                  :header-cell-style="{
                    background: '#eef1f6',
                    color: '#606266'
                  }"
                >
                  <template #empty>
                    <el-empty
                      :image-size="40"
                      description="暂无数据"
                    ></el-empty>
                  </template>
                  <el-table-column type="index" label="序号" />
                  <el-table-column
                    prop="time"
                    label="起止时间"
                  ></el-table-column>
                  <el-table-column
                    prop="content"
                    label="研究内容"
                  ></el-table-column>
                  <el-table-column
                    prop="goal"
                    label="预期目标"
                  ></el-table-column>
                  <el-table-column prop="isDone" label="是否完成">
                    <template #default="{ row }">
                      {{ row.isDone === "1" ? "是" : "否" }}
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="doneTime"
                    label="完成时间"
                  ></el-table-column>
                  <el-table-column
                    prop="doneDes"
                    label="完成情况"
                  ></el-table-column>
                  <el-table-column prop="attachment" label="附件">
                    <template #default="{ row }">
                      <el-link
                        v-for="(item, index) in row.attachment"
                        :key="index"
                        @click="handlePreview(item)"
                        >{{ item.fileName }}</el-link
                      >
                    </template>
                  </el-table-column>
                </el-table>
              </el-form-item>
            </el-col>
          </el-row>
        </div>

        <div v-if="model.formData.reviewStageName === '项目验收'">
          <el-row>
            <el-col :xl="24" :lg="24">
              <el-form-item label="项目目标及考核指标">
                <check-table-list
                  :data="checkTableData"
                  :isEdit="false"
                ></check-table-list>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xl="16" :lg="24">
              <el-form-item label="项目验收报告">
                <el-link
                  v-for="(item, index) in model.reviewDefaultFileList"
                  :key="index"
                  @click="handlePreview(item)"
                  >{{ item.fileName }}</el-link
                >
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xl="16" :lg="24">
              <el-form-item label="项目经费决算报告">
                <el-link
                  v-for="(item, index) in model.approvalDefaultFileList"
                  :key="index"
                  @click="handlePreview(item)"
                  >{{ item.fileName }}</el-link
                >
              </el-form-item>
            </el-col>
          </el-row>
        </div>

        <div v-if="model.formData.reviewStageName === '项目后评价'">
          <BasicsInfo :projectInfo="projectInfo" :isApplication="true" />
        </div>

        <div v-if="model.formData.reviewStageName === '项目变更'">
          <el-row>
            <el-col :xl="16" :lg="24">
              <el-form-item label="变更事由">
                {{ model.changeFormData.alterationReason }}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xl="16" :lg="24">
              <el-form-item label="变更原因">
                {{ model.changeFormData.alterationMatters }}
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :xl="16" :lg="24">
              <el-form-item label="变更时间">
                {{ model.changeFormData.alterationTime }}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xl="16" :lg="24">
              <el-form-item label="备注">
                {{ model.changeFormData.remark }}
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        <div v-if="model.formData.reviewStageName === '项目终止'">
          <el-row>
            <el-col :xl="16" :lg="24">
              <el-form-item label="终止事由">
                {{ model.changeFormData.alterationReason }}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xl="16" :lg="24">
              <el-form-item label="终止原因">
                {{ model.changeFormData.alterationMatters }}
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :xl="16" :lg="24">
              <el-form-item label="终止时间">
                {{ model.changeFormData.alterationTime }}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xl="16" :lg="24">
              <el-form-item label="备注">
                {{ model.changeFormData.remark }}
              </el-form-item>
            </el-col>
          </el-row>
        </div> -->
        <el-row>
          <el-col :xl="24" :lg="24">
            <el-form-item label="专家评审意见">
              <el-table
                :data="rvwUserList"
                border
                :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
              >
                <el-table-column type="index" width="50" />
                <el-table-column prop="userName" label="专家姓名" />
                <el-table-column prop="deptName" label="所属单位" />
                <el-table-column prop="expertGroupName" label="专家组别" />
                <el-table-column prop="expertCategoryName" label="专家类型" />

                <el-table-column
                  prop="reviewCommentsName"
                  label="专家综合评审结论"
                />
                <el-table-column label="评审意见和建议">
                  <template #default="{ row }">
                    <el-link
                      type="primary"
                      @click="openDetail(row)"
                      :disabled="!row.reviewCommentsName"
                      >查看</el-link
                    >
                  </template>
                </el-table-column>
                <el-table-column prop="reviewFinishTime" label="评审时间" />
              </el-table>
            </el-form-item>
          </el-col>
        </el-row>
        <div v-if="nodeId === 'ACT_012' || nodeId === 'END'">
          <el-row>
            <el-col :xl="24" :lg="24">
              <el-form-item label="评审意见">
                {{ model.otherData.reviewCategoryName }}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xl="24" :lg="24">
              <el-form-item label="汇总专家评审意见">
                <el-link
                  style="display: block"
                  v-for="(item, index) in model.otherData
                    .reviewTemplateAttachmentArr"
                  :key="index"
                  @click="handlePreview(item)"
                  >{{ item.fileName }}</el-link
                >
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xl="24" :lg="24">
              <el-form-item label="备注">
                {{ model.otherData.remark }}
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </div>
    </el-card>

    <br />
    <el-card>
      <template #header>
        <div class="card-box-header">
          <span> 评审流程</span>
          <div v-if="show5" @click="show5 = !show5" class="header-btn">
            收起
            <i class="el-icon-arrow-down"></i>
          </div>
          <div v-else @click="show5 = !show5" class="header-btn">
            展开
            <i class="el-icon-arrow-right"></i>
          </div>
        </div>
      </template>
      <div v-if="steps && steps.length">
        <el-collapse-transition>
          <StatusInfo
            :currentStep="currentStep"
            :steps="steps"
            :isSkip="isSkipLx"
          />
        </el-collapse-transition>
      </div>
    </el-card>
    <br />

    <el-card>
      <template #header>
        <div class="card-box-header">
          <span> 流转记录</span>
          <div v-if="show6" @click="show6 = !show6" class="header-btn">
            收起
            <i class="el-icon-arrow-down"></i>
          </div>
          <div v-else @click="show6 = !show6" class="header-btn">
            展开
            <i class="el-icon-arrow-right"></i>
          </div>
        </div>
      </template>
      <div v-show="show6">
        <el-collapse-transition>
          <approval-info :activities="approveRecord" />
        </el-collapse-transition>
      </div>
    </el-card>
  </el-form>
  <el-dialog
    :custom-class="'expert-dialog'"
    v-model="model.dialogTableVisible"
    title="评审意见和建议"
  >
    <el-form>
      <p class="dialog-title">评审结论</p>
      <el-card>
        <el-form-item>
          <template #label>
            <span>综合评审结论：</span>
          </template>
          {{ model.target.reviewCommentsName }}
        </el-form-item>
      </el-card>
      <p class="dialog-title">评审意见</p>
      <el-card v-if="model.target.expertCategoryCode === '1'">
        <!-- 项目立项 -->
        <div v-if="model.formData.reviewStageCode == 2">
          <el-form-item>
            <template #label>
              <div class="label-text">
                <span>创新性：</span>
                <!-- <p>（创新点或者专利、标准等）</p> -->
              </div>
            </template>
            {{ model.target.tcnInnovation }}
          </el-form-item>
          <el-form-item>
            <template #label>
              <div class="label-text">
                <span>必要性：</span>
                <!-- <p>（技术在行业内的先进性）</p> -->
              </div>
            </template>
            {{ model.target.tcnAdvance }}
          </el-form-item>
          <el-form-item>
            <template #label>
              <div class="label-text">
                <span>创造价值：</span>
                <!-- <p>（市场价值、降低成本、提升效率等）</p> -->
              </div>
            </template>
            {{ model.target.tcnJbzx }}
          </el-form-item>
          <el-form-item>
            <template #label>
              <div class="label-text">
                <span>可行性：</span>
              </div>
            </template>
            {{ model.target.ext1 }}
          </el-form-item>
          <el-form-item>
            <template #label>
              <div class="label-text">
                <span>团队能力：</span>
              </div>
            </template>
            {{ model.target.ext2 }}
          </el-form-item>
        </div>
        <!-- 项目验收 -->
        <div v-else-if="model.formData.reviewStageCode == 4">
          <el-form-item>
            <template #label>
              <div class="label-text">
                <span>项目完成情况：</span>
              </div>
            </template>
            {{ model.target.ext3 }}
          </el-form-item>
          <el-form-item>
            <template #label>
              <div class="label-text">
                <span>项目产出：</span>
              </div>
            </template>
            {{ model.target.ext4 }}
          </el-form-item>
          <el-form-item>
            <template #label>
              <div class="label-text">
                <span>成果影响：</span>
              </div>
            </template>
            {{ model.target.ext5 }}
          </el-form-item>
          <el-form-item>
            <template #label>
              <div class="label-text">
                <span>综合管理：</span>
              </div>
            </template>
            {{ model.target.ext6 }}
          </el-form-item>
        </div>
        <!-- 其他项目阶段 -->
        <div v-else>
          <el-form-item>
            <template #label>
              <div class="label-text">
                <span>创新性：</span>
              </div>
            </template>
            {{ model.target.tcnInnovation }}
          </el-form-item>
          <el-form-item>
            <template #label>
              <div class="label-text">
                <span>必要性：</span>
              </div>
            </template>
            {{ model.target.tcnAdvance }}
          </el-form-item>
          <el-form-item>
            <template #label>
              <div class="label-text">
                <span>创造价值：</span>
              </div>
            </template>
            {{ model.target.tcnJbzx }}
          </el-form-item>
        </div>
      </el-card>
      <el-card v-if="model.target.expertCategoryCode === '2'">
        <el-form-item>
          <template #label>
            <div class="label-text2">
              <span>经济性：</span>
              <!-- <p></p> -->
            </div>
          </template>
          {{ model.target.ecoRational }}
        </el-form-item>
        <el-form-item>
          <template #label>
            <div class="label-text2">
              <span>符合性：</span>
              <!-- <p></p> -->
            </div>
          </template>
          {{ model.target.ecoAccurate }}
        </el-form-item>
        <el-form-item>
          <template #label>
            <div class="label-text2">
              <span>相关性：</span>
              <!-- <p>（是否有预算？）</p> -->
            </div>
          </template>
          {{ model.target.ecoCompliance }}
        </el-form-item>
      </el-card>
      <p class="dialog-title">对本项目的意见</p>
      <el-card>
        {{ model.target.reviewComments }}
      </el-card>
      <p class="dialog-title">附件</p>
      <el-card>
        <ecm-upload
          v-if="model.target.reviewAttachment"
          :files="
            model.target.reviewAttachment
              ? JSON.parse(model.target.reviewAttachment)
              : []
          "
          :docid="docid"
          disabled
        ></ecm-upload>
        <span v-else>无</span>
      </el-card>
    </el-form>
  </el-dialog>
</template>

<script lang="ts" setup>
import { ref, reactive, onMounted } from "vue";
import { useRouter, useRoute } from "vue-router";
import StatusInfo from "/@/components/StatusInfo/index.vue";
import { flowStatusObj } from "/@/components/StatusInfo/type";
import ApprovalInfo from "/@/components/ApprovalInfo/index.vue";
import CommonInfo from "../components/commonInfo.vue";
import EcmUpload from "/@/components/ecmUpload/index.vue";
import {
  getExpertDetail,
  getApproveHistory,
  getExpertRvwOpinion,
  getExpertList
} from "/@/api/project";
import { cloneDeep } from "lodash-es";
// import NotifMessage from "/@/utils/message/notification";
const router = useRouter();
const route = useRoute();
const formRef = ref<HTMLFormElement | null>(null) as any;
let show1 = ref<boolean>(true);
let show5 = ref<boolean>(true);
let show6 = ref<boolean>(true);
let docid = window["ecmDocType"].project;
const isDisabled = ref<boolean>(false);
const isSkipLx = route.query.isSkipLx;
const currentStep = ref(0);
const steps = ref([]);
const rvwUserList = ref([]);
const approveRecord = ref([]);
const nodeId = route.query.nodeId ? route.query.nodeId : "ACT_010";
const formRules = ref({
  projectReviewOption: [
    { required: true, message: "请输入申请意见", trigger: "change" }
  ]
  // oaApproveOption: [
  //   { required: true, message: "请选择审批意见", trigger: "change" }
  // ],
  // oaApproveFile: [{ required: true, message: "请上传附件", trigger: "change" }]
});
const model = reactive({
  approvalDefaultFileList: [],
  reviewDefaultFileList: [],
  flowType: "3009",
  dialogTableVisible: false,
  target: null,
  evaludate: {
    memberList: [],
    evaluationTime: "",
    remark: "",
    evaluationMembers: [],
    evaluationResult: "",
    defaultFileList: [],
    evaluationReport: []
  },
  changeFormData: {
    alterationMatters: "",
    alterationReason: "",
    alterationTime: "",
    remark: ""
  },
  formData: {
    projectName: "",
    projectCode: "",
    reviewStageName: "",
    reviewRoundName: "",
    reviewStageCode: null
  },
  otherData: {
    reviewCategoryName: "",
    reviewTemplateAttachmentArr: [],
    remark: ""
  }
});

const handlePreview = (item: any) => {
  if (item.response) {
    window.open(
      `${location.origin}${location.pathname}#/online?uuidFile=${item?.response.data.uuidFile}&fileName=${item?.response.data.fileName}`
    );
  } else {
    window.open(
      `${location.origin}${location.pathname}#/online?uuidFile=${item.uuidFile}&fileName=${item.fileName}`
    );
  }
};
const handleBack = () => {
  router.replace("/project/expert");
};

const openDetail = item => {
  model.target = item;
  model.dialogTableVisible = true;
};

const getOther = async () => {
  const params = {
    projectManageId: route.query.projectId,
    reviewStageCode: model.formData.reviewStageCode,
    pageSize: 0
  };
  const res = await getExpertList(params);
  if (res.code === 200) {
    let data = res.data.list[0];
    model.otherData.remark = data.remark || "";
    model.otherData.reviewTemplateAttachmentArr =
      data.reviewTemplateAttachmentArr || [];
    model.otherData.reviewCategoryName = data.reviewCategoryName || "";
  }
};

//查询项目详情
const initExpertInfo = async () => {
  const expertId = route.query.id;
  const { code, data } = await getExpertDetail({ id: expertId });
  getStep();
  if (code === 200) {
    model.formData = cloneDeep(data);
    model.formData.projectName = data.projectName;
    model.formData.projectCode = route.query.projectCode as string;
    model.formData.reviewRoundName = data.reviewRoundName;
    model.formData.reviewStageName = data.reviewStageName;
    // debugger
  }
};

//查询流程审批记录
const getApproveHistoryList = async () => {
  const instanceId = route.query.instanceId;
  if (instanceId) {
    const { code, data } = await getApproveHistory(instanceId);
    if (code === 200) {
      approveRecord.value = data;
    }
  }
};

//获取流程转态
const getStep = () => {
  steps.value = flowStatusObj[model.flowType];
  if (steps.value && steps.value.length) {
    steps.value.forEach((item, index) => {
      if (item.nodeId === nodeId) {
        currentStep.value = +index;
      }
    });
  }
};

const getRvwOpinion = async () => {
  const expertId = route.query.id;
  const { code, data } = await getExpertRvwOpinion({
    expertRvwId: expertId,
    pageSize: 0
  });
  if (code === 200) {
    rvwUserList.value = data.list;
  }
  // const  getExpertRvwOpinion
};
onMounted(async () => {
  await getRvwOpinion();
  await initExpertInfo();
  // getStep();
  await getOther();
  await getApproveHistoryList();
});
</script>

<style lang="scss" scoped>
.empt-content {
  height: calc(100vh - 200px);
  width: 100%;
}

.card-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-box-header {
  display: flex;
  justify-content: space-between;
  align-items: center;

  .header-btn {
    font-size: 14px;
    cursor: pointer;
  }
}

.dialog-title {
  margin: 10px 0;
  font-size: 18px;
}

:deep .expert-dialog .el-dialog__body {
  padding-top: 0 !important;
}

.label-text {
  text-align: right;
}
</style>
